Skip to content

[ENHANCEMENT] TimeSeriesChart: add query name support for query settings#585

Open
Gladorme wants to merge 6 commits into
perses:mainfrom
Gladorme:named-queries
Open

[ENHANCEMENT] TimeSeriesChart: add query name support for query settings#585
Gladorme wants to merge 6 commits into
perses:mainfrom
Gladorme:named-queries

Conversation

@Gladorme

@Gladorme Gladorme commented Feb 26, 2026

Copy link
Copy Markdown
Member

Description

Depends on: perses/shared#69

Add support for query name in query settings + deprecating queryIndex.

Migration guide:

  • Via the UI:
    Go the dashboard, edit timeserieschart panel, go to query settings, update any value and save (it will migrate all query settings of the panel to queryName)

  • Manually:
    Replace queryIndex by queryName.
    Replace number by string Query #<index + 1> or use helper defaultQueryName.
    Example: queryIndex: 0 become queryName: 'Query #1'.

Screenshots

Queries:
image

Query settings:
image

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the
    following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, DOC,IGNORE.
  • All commits have DCO signoffs.

UI Changes

  • Changes that impact the UI include screenshots and/or screencasts of the relevant changes.
  • Code follows the UI guidelines.

@Gladorme Gladorme changed the title Named queries ENHANCEMENT/BREAKINGCHANGE] timneserieschart: add query name support for query settings Feb 27, 2026
@Gladorme Gladorme changed the title ENHANCEMENT/BREAKINGCHANGE] timneserieschart: add query name support for query settings [ENHANCEMENT/BREAKINGCHANGE] timneserieschart: add query name support for query settings Feb 27, 2026
@Gladorme Gladorme changed the title [ENHANCEMENT/BREAKINGCHANGE] timneserieschart: add query name support for query settings [ENHANCEMENT/BREAKINGCHANGE] timeserieschart: add query name support for query settings Feb 27, 2026
@AntoineThebaud AntoineThebaud changed the title [ENHANCEMENT/BREAKINGCHANGE] timeserieschart: add query name support for query settings [ENHANCEMENT/BREAKINGCHANGE] TimeSeriesChart: add query name support for query settings Mar 11, 2026
Gladorme added 3 commits June 26, 2026 17:23
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
… for query settings

Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
@Gladorme Gladorme force-pushed the named-queries branch 2 times, most recently from cc39a7d to f6d19a8 Compare June 26, 2026 15:57
@Gladorme Gladorme marked this pull request as ready for review June 26, 2026 15:57
@Gladorme Gladorme requested review from a team, AntoineThebaud and Nexucis as code owners June 26, 2026 15:57
@Gladorme Gladorme requested review from shahrokni and removed request for a team June 26, 2026 15:57
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
seriesIndex: 0,
querySettings: {
queryIndex: 0,
queryName: defaultQueryName(0),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a massive breaking change. This will break every dashboard created without dashboard as code or by migrating from Grafana.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I will check if I can keep old data model

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I remember why I did this change. We can't keep index, because it will cause issue when re-ordering queries with query settings. I will rename queryName to queryIndex, but result will be the same => they will need to update queryIndex.

Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
@Gladorme Gladorme changed the title [ENHANCEMENT/BREAKINGCHANGE] TimeSeriesChart: add query name support for query settings [ENHANCEMENT] TimeSeriesChart: add query name support for query settings Jun 29, 2026
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Comment on lines +66 to +68
if (querySettings.queryIndex === undefined) {
return querySettings;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the idea behind this condition was that, if queryIndex was undefined then queryName would already exist. So, simply return the current one. However, this could go wrong. The QuerySettingsOptions object could be completely empty due to the fact that all fields are optional. Therefore, regardless of how queryName is generated, it is still technically possible to receive an empty object. This may open the door to bugs in future.

/* ALL FIELDS ARE OPTIONAL */
export interface QuerySettingsOptions {
  queryName?: string;
  /**
   * @deprecated Use `queryName` instead.
   */
  queryIndex?: number;
  colorMode?: 'fixed' | 'fixed-single';
  colorValue?: string;
  lineStyle?: LineStyleType;
  areaOpacity?: number;
  format?: FormatOptions;
}

So, maybe?

if (querySettings.queryIndex === undefined && querySettings.queryName!==undefined)

Comment on lines 42 to 50
export interface QuerySettingsOptions {
queryIndex: number;
queryName?: string;
/**
* @deprecated Use `queryName` instead.
*/
queryIndex?: number;
colorMode?: 'fixed' | 'fixed-single';
colorValue?: string;
lineStyle?: LineStyleType;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that from the backend perspective a none-optional queryName could be problematic and probably a breaking change.

queryName?: strings.MinRunes(1)

However, from the UI perspective this field looks mandatory and there is no way to drop it. This means that from UI we could still keep it as a none-optional field.

Image

The fact that we could have empty object query settings is not a good idea in my opinion, although from the UI a query name is always guaranteed.

export interface QuerySettingsOptions {
  queryName?: string;
  /**
   * @deprecated Use `queryName` instead.
   */
  queryIndex?: number;
  colorMode?: 'fixed' | 'fixed-single';
  colorValue?: string;
  lineStyle?: LineStyleType;
  areaOpacity?: number;
  format?: FormatOptions;
}

Comment on lines +65 to 70
queryName?: strings.MinRunes(1)
// queryIndex is deprecated, use queryName instead. Kept for backward compatibility.
queryIndex?: int & >=0
colorMode?: "fixed" | "fixed-single" // NB: "palette" could be added later
colorValue?: =~"^#(?:[0-9a-fA-F]{3}){1,2}$" // hexadecimal color code
lineStyle?: #lineStyle

@shahrokni shahrokni Jun 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the following payload that I crafted and sent to the backend.
Since the schema is fully optional now, such a payload is persisted. I think this should be avoided. If we insist that we should keep all fields optional, then maybe we should intercept the req and drop the querySettings completely. (I am just discussing the payload point of view)

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants